package com.cse.index;

import java.io.File;

import org.apache.lucene.document.*;

import com.cse.core.Product;


public class ProductDocument {

	private static final String PRODUCT_ID = "productid";

	private static final String INDEX_TIME = "indextime";

	private static final String CATEGORY = "category";

	private static final String PRODUCT_BRAND = "brand";
	
	private static final String PRODUCT_CONTENT = "content";
	
	private static final String PRODUCT_PRICE = "price";
	
	private static final String PRODUCT_INFO = "info";
	
	
	


	public static Document buildProductDocument(Product product) {
		Document doc = new Document();


		long mills = System.currentTimeMillis();
		Field indextime = new Field(INDEX_TIME, mills + "", Field.Store.YES,
				Field.Index.UN_TOKENIZED);



		Field category = new Field(CATEGORY, product.getCategory(),
				Field.Store.YES, Field.Index.TOKENIZED);

		Field brand = new Field(PRODUCT_BRAND, product.getBrand(),
				Field.Store.YES, Field.Index.TOKENIZED);
		
		Field price = new Field(PRODUCT_PRICE, product.getPrice(),
				Field.Store.YES, Field.Index.TOKENIZED);
		
		Field info = new Field(PRODUCT_INFO, product.getContent(),
				Field.Store.YES, Field.Index.TOKENIZED);
	
		//将价格和内容作为索引内容统一写入
		Field content = new Field(PRODUCT_CONTENT, product.getContent()+product.getPrice(), 
				Field.Store.YES, Field.Index.TOKENIZED);

		doc.add(indextime);
		doc.add(category);
		doc.add(brand);
		doc.add(price);
		doc.add(info);
		doc.add(content);

		return doc;

	}

}
